<template>
    <a-drawer v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
              :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
              :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
              :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">
        <a-form ref="formRef" :model="formState" layout="vertical" :rules="STRATEGY_EDIT.RULES">
            <a-row :gutter="12">

                <a-col :span="24">
                    <a-form-item label="攻略标题" field="title">
                        <a-input v-model="formState.title" allow-clear placeholder="请填攻略标题"/>
                    </a-form-item>
                </a-col>
                <a-col :span="12">
                    <a-form-item label="攻略分类" field="kind">


                        <smart-dict  v-model="formState.kind" :url="DictOptions.StrategyKind" allow-clear placeholder="攻略分类"/>
                    </a-form-item>
                </a-col>
                <a-col :span="12">
                    <a-form-item label="显示排序值" field="sort" tooltip="显示排序值越小 显示越靠前">
                        <a-input-number :min="0" :max="100" v-model="formState.sort" allow-clear placeholder="请设置显示排序值"/>
                    </a-form-item>
                </a-col>


                <a-col :span="24">
                    <a-form-item label="BANNER图片" field="banner">
                        <smart-upload-image v-model="formState.banner" :limit="1"/>
                    </a-form-item>
                </a-col>

                <a-col :span="24">
                    <a-form-item label="攻略正文" field="content">
                        <a-textarea v-model="formState.content" auto-size placeholder="请填写攻略正文"/>
                    </a-form-item>
                </a-col>
            </a-row>


        </a-form>
        <!--表单结束-->
    </a-drawer>
</template>

<script lang="ts" setup>

import {EditDrawer} from '@/libs/core'

import {STRATEGY_EDIT} from "../resource/form";
import {SystemHttp} from '../resource/http'
import {DictOptions} from "@/libs/options";

const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])

const {addStrategy, updateStrategy} = SystemHttp
const config = {tplRecord: STRATEGY_EDIT.BODY, rawRecord: props.record, rowKey: 'id', emit}

const service = new EditDrawer(config).setAddRequest(addStrategy).setUpdateRequest(updateStrategy)
const {formRef, formState, LAYER, isUpdate, onCancel, onSubmit} = service
LAYER.title = isUpdate ? '修改攻略' : '新建攻略'
</script>
